#include "lengthOfLastWord.h"

int lengthOfLastWord(std::string s)
{
	int left = 0;
	int right = 0;
	int length = s.length();

	if (length < 1)
	{
		return length;
	}

	left = length - 1;
	right = length - 1;

	bool isLastEnd = false;

	for (; left >= 0; left--)
	{
		if (isLastEnd == false)
		{
			if (s[right] == ' ')
			{
				right--;
				continue;
			}

			left = right;
			isLastEnd = true;
		}
		

		if (left == 0 || s[left - 1] == ' ')
		{
			break;
		}
	}

	return (right - left + 1);
}
